/**
 * 226. 翻转二叉树
 * https://leetcode-cn.com/problems/invert-binary-tree/
 */
const { displayTreeNode, createTreeNode } = require('../../libs/public');

/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
function invertTree(root) {
  if (!root) return root;
  const temp = root.left;
  root.left = root.right;
  root.right = temp;
  invertTree(root.left);
  invertTree(root.right);
  return root;
}

console.log(displayTreeNode(invertTree(createTreeNode([4, 2, 7, 1, 3, 6, 9]))) === '[4,7,2,9,6,3,1]');
console.log(displayTreeNode(invertTree(createTreeNode([2, 1, 3]))) === '[2,3,1]');
console.log(displayTreeNode(invertTree(createTreeNode([]))) === '[]');
